﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Helper;
using System.Data;
using System.Runtime.Serialization;
using CoreData;
namespace OpenIDHostController.DataContract
{
    [DataContract]
    public partial class vwusersContract
    {
        [DataMember]
        public long id { get; set; }
        [DataMember]
        public string username { get; set; }
        [DataMember]
        public string password { get; set; }
        [DataMember]
        public string fullname { get; set; }
        [DataMember]
        public string email { get; set; }
        [DataMember]
        public string address { get; set; }
        [DataMember]
        public string indentitycard { get; set; }
        [DataMember]
        public string numberphone { get; set; }
        [DataMember]
        public DateTime createdate { get; set; }
        [DataMember]
        public DateTime modifieddate { get; set; }
        [DataMember]
        public DateTime birthday { get; set; }
        [DataMember]
        public bool active { get; set; }
        [DataMember]
        public long groupid { get; set; }
        [DataMember]
        public string groupname { get; set; }
        [DataMember]
        public long moduleid { get; set; }
        [DataMember]
        public string modulename { get; set; }
        [DataMember]
        public string role { get; set; }
        [DataMember]
        public long serviceid { get; set; }
        [DataMember]
        public string servicename { get; set; }
         
        public vwusersContract()
        {
            username = "";
            password = "";
            fullname = "";
            email = "";
            address = "";
            indentitycard = "";
            numberphone = "";
            active = true;
            groupname = "";
            modulename = "";
            servicename = "";
        }

        public static vwusersContract ToContract(vwusers data)
        {
            try
            {
                var model = ConvertObject.ConvertToObject(new vwusersContract());
                Helper.ConvertObject.ConvertEntityToModel(data, ref model);
                return (vwusersContract)model;
            }
            catch
            {
                return null;
            }
        }
        public static vwusers ToCoreData(vwusersContract data)
        {
            try
            {
                var model = ConvertObject.ConvertToObject(new vwusers());
                Helper.ConvertObject.ConvertEntityToModel(data, ref model);
                return (vwusers)model;
            }
            catch
            {
                return null;
            }
        }

        public static IList<vwusers> ToListCoreData(IList<vwusersContract> data)
        {
            var list = new List<vwusers>();
            foreach (var item in data)
            {
                var model = ConvertObject.ConvertToObject(new vwusers());
                Helper.ConvertObject.ConvertEntityToModel(item, ref model);
                if (model != null)
                {
                    list.Add((vwusers)model);
                }
            }
            if (list.Count <= 0)
                return null;
            return list;
        }
        public static IList<vwusersContract> ToListConTract(IList<vwusers> data)
        {
            var list = new List<vwusersContract>();
            foreach (var item in data)
            {
                var model = ConvertObject.ConvertToObject(new vwusersContract());
                Helper.ConvertObject.ConvertEntityToModel(item, ref model);
                if (model != null)
                {
                    list.Add((vwusersContract)model);
                }
            }
            if (list.Count <= 0)
                return null;
            return list;
        }
    }
}
